<?php
/***********************************************************************
 * @package    	IvanEngine
 * @subpackage 	Core
 * @author     	Ivan <ivanzx@msn.com>
 * @created    	2010-05-17
 ***********************************************************************/
if(defined("IVANENGINE_CORE_VALIDATOR_BOOLEAN"))
	die("Redefinition macro in :".__FILE__."(".__LINE__.")");
define("IVANENGINE_CORE_VALIDATOR_BOOLEAN", true);

require_once (dirname(__FILE__).'/ValidatorBase.php');

class CValidatorBoolean extends CValidatorBase
{
	const NO_TrueValues		= 'NO_TrueValues';
	const NO_FalseValues	= 'NO_FalseValues';
	
	protected function Initialize($options = array(), $messages = array())
  	{
  		parent::Initialize($options, $messages);

    	$this->AddOption(self::NO_TrueValues, array('true', 't', 'yes', 'y', 'on', '1'));
    	$this->AddOption(self::NO_FalseValues, array('false', 'f', 'no', 'n', 'off', '0'));

    	$this->SetOption(self::NO_Required, false);
    	$this->SetOption(self::NO_EmptyValue, false);
  	}
  	
	protected function DoVerify($value) 
	{
    	if (in_array($value, $this->GetOption(self::NO_TrueValues)))
	    {
	      	return true;
	    }
	
	    if (in_array($value, $this->GetOption(self::NO_FalseValues)))
	    {
	      	return false;
	    }

    	throw new CExceptionValidator($this, self::NM_Invalid, array('value' => $value));
	}
}

?>